package com.gxuwz.medical.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.alibaba.fastjson.JSON;
import com.gxuwz.medical.domain.user.User;
/**
 * 登录验证控制模块
 * @author 演示
 *
 */

public class LoginServlet extends BaseServlet {

	private static final Logger logger = LogManager.getLogger(LoginServlet.class);
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		login(request, response);
		
	}
	private void login(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String path="login.jsp";
		try{
			String userid = request.getParameter("userid");
			String pwd = request.getParameter("pwd");			
			User user = new User();
			user = user.login(userid, pwd);
			if(user!=null){
				user=user.query();
				request.getSession().setAttribute("user", user);
				path="index.jsp";
				}
		}catch(Exception e){
			e.printStackTrace();
			path="error/500.jsp";
		} //跳转页面
		    process(request, response, path);
	}
}
